﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SaleOnlineSystem.Controls
{
    public partial class BoxContact : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void tbnSend_Click(object sender, EventArgs e)
        {
            int nextid = Convert.ToInt32(DAL.DCollector.DBCollector.Instance.getNextID("tbl_Bank", "Bank_ID"));
            string emailcontact = txtEmaiContact.Text;
            if (LIB.Validate.checkEmail(emailcontact) == true)
            {
                if (!txtDetails.Text.Equals(""))
                {
                    if (nextid == 0)
                    {
                        string detais = txtDetails.Text;
                        string value = "'" + emailcontact + "',N'" + detais + "'";
                        List<string> values = new List<string>();
                        values.Add(value);
                        DAL.DCollector.DBCollector.Instance.StoredProcedureInsertByRows("tbl_Contact", "insertemployee", values, false);
                        Response.Redirect(Request.Url.ToString());
                    }
                    else
                    {
                        int idnext = nextid + 1;
                        string detais = txtDetails.Text;
                        string value = "" + idnext + ",'" + emailcontact + "',N'" + detais + "'";
                        List<string> values = new List<string>();
                        values.Add(value);
                        DAL.DCollector.DBCollector.Instance.StoredProcedureInsertByRows("tbl_Contact", "insertemployee", values, false);
                        Response.Redirect(Request.Url.ToString());
                    }

                }
                else
                {
                    txtDetails.Text = "Bạn vui lòng nhập nội dung liên hệ";
                }
            }
            else
            {
                txtEmaiContact.Text = "Email không hợp lệ";
            }
        }
    }
}